package edu.umd.fosite.data;

public class FiniteLatticeDouble2D implements LatticeDouble2D {

	private double[][] data;

	public FiniteLatticeDouble2D(int xDim, int yDim, double init) {
		data = new double[xDim][yDim];
		for (int x = 0; x < xDim; x++)
			for (int y = 0; y < yDim; y++)
				data[x][y] = init;
	}

	public FiniteLatticeDouble2D(int xDim, int yDim, Generator generator) {
		data = new double[xDim][yDim];
		for (int x = 0; x < xDim; x++)
			for (int y = 0; y < yDim; y++)
				data[x][y] = generator.gen(x, y);
	}

	@Override
	public double get(int x, int y) {
		try {
			return data[x][y];
		} catch (Exception e) {
			return 0;
		}
	}

	public void set(int x, int y, double v) {
		data[x][y] = v;
	}

	public int getXDim() {
		return data.length;
	}

	public int getYDim() {
		return data[0].length;
	}

	public interface Generator {

		public double gen(int x, int y);

	}

}
